import axios from 'axios'
import { ElMessage } from 'element-plus'
import Qs from 'qs'

const instance = axios.create({
  baseURL: import.meta.env.VITE_APP_URL,
  timeout: 60000,
  headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }
})
const request = ({ url, method = 'GET', params = {} }) => {
  return new Promise((resolve, reject) => {
    const requestBody = method.toLowerCase() === 'get' ? 'params' : 'data';
    const methods = {post: 'data', get: 'params'}
    console.log(params)
    const result = instance({ url, method: 'post', data: {goodsId: 2, title: "笔记本大大", price: "撒大声地", thumbnail: "/images/2_521.jpg", goodsDetail: "<p><img src=\"https://www.boxuegu.com/_nuxt/img/hea… undefined\"></p><p>\n</p><p>大厦</p><p>\n</p><p>\n</p>"} });
    result.then(value => resolve(value), reason => ElMessage.error(JSON.stringify(reason)));
  });
};

export const GOODSLIST = async params => await request({url: '/goods', params})

export const ADDGOODS = async params => await request({url: '/goods/add', method: "post", params})

export const EDITGOODS = async params => await request({url: '/goods/edit', method: "post", params})